import { login } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
// import { resetRouter } from '@/router'

const state = {
    token: getToken() || ''
}

const mutations = {
    settoken: (state, newtoken) => {
        state.token = newtoken
        setToken(newtoken)
    },
    removetoken(state) {
        state.token = ''
        removeToken()
    },
}

const actions = {
    // 走登录接口
    async getlogin({ commit }, data) {
        const res = await login(data)
        console.log(res)
        commit('settoken', res.data.data.token.token)
        setToken(res.data.data.token.token)

    },
    logoutt({ commit }) {
        // 删除token
        commit('removeToken')
    }
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}